﻿using ExamRoomAllocationManagement.Services;
using Microsoft.AspNetCore.Mvc;
using Xmu.ExamRoomAllocationManagement.Services;
using Xmu.Stores.Models;

namespace UserStores.Controllers
{
    [Route("/api/[controller]")]
    public class RegistrationController : Controller
    {
        private RegistrationService registrationService;
        public RegistrationController(RegistrationService registrationService)
        {
            this.registrationService = registrationService;
        }

        [HttpPost]
        public IActionResult AddRegistration([FromBody] Registration registration)
        {
            var (success, msg) = registrationService.AddRegistration(registration);
            if (success) return Ok();
            else return BadRequest(msg);
        }

        [HttpGet("all")]
        public IActionResult GetAllRegistions()
        {
            (object data, object msg) = registrationService.GetAllRegistrations();
            return Ok(new
            {
                msg,
                data
            });
        }

        [HttpGet]
        public IActionResult GetAllRegistions([FromQuery] int pageIndex, [FromQuery] int pageSize)
        {
            (object data, object msg) = registrationService.GetRegistrations(pageSize, pageIndex);
            return Ok(new
            {
                msg,
                data
            });
        }

        [HttpDelete("empty")]
        public IActionResult EmptyRegistration()
        {
            (object data, object msg) = registrationService.EmptyRegistration();
            return Ok(new
            {
                msg,
                data
            });
        }
    }
}
